package com.rpinfo.editalog.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author camilo
 */
public class JaxbUtil {

  public void gerarXml(Object objeto, File arquivo) throws JAXBException, FileNotFoundException {
    JAXBContext context = JAXBContext.newInstance("contexto");
    Marshaller marshaller = context.createMarshaller();
    marshaller.marshal(objeto, new FileOutputStream(arquivo));
  }

  public Object lerXml(Object objeto, File arquivo) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance("contexto");
    Unmarshaller unmarshaller = context.createUnmarshaller();
    return objeto = unmarshaller.unmarshal(arquivo);
  }
}
